package com.hqyj.module.clock.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.module.clock.dao.ClockDao;
import com.hqyj.module.clock.pojo.ClockTable;
import com.hqyj.module.clock.pojo.NewClockTable;
import com.hqyj.module.clock.pojo.SearchBean;
import com.hqyj.module.clock.service.ClockService;
import com.hqyj.module.holiday.pojo.Holiday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author lap
 * @version 1.0
 * @date 2021/9/29 16:33
 */
@Service
public class ClockServiceImpl implements ClockService {
    @Autowired
    private ClockDao clockDao;

    @Override
    public Map<String,Object> getClock(int userId,String nowDay) {
        Map<String,Object> map = new HashMap<>();

        String[] str = nowDay.split("/");
        String s = str[1];
        String s3= str[2];
        if(Integer.parseInt(s)<10){
            s="0"+s;
        }
        if(Integer.parseInt(s3)<10){
            s3="0"+s3;
        }
        String time = "%"+str[0]+"-"+s+"-"+s3+"%";

        List<NewClockTable> clock = clockDao.getClock(userId, time);
        if(clock.size() !=0){
            map.put("info","已签到");
            if(clock.get(0).getEndTime() !=null){
                map.put("msg","已打卡下班");
            }else {
                map.put("msg","未打卡下班");
            }
        }else {
            map.put("info","未签到");
        }
        return map;
    }

    @Override
    public Map<String,Object> insertClock(ClockTable clock) {
        Map<String,Object> map = new HashMap<>();
        Integer integer = clockDao.insertClock(clock);
        if(integer>0){
            map.put("info","操作成功");
        }
        return map;
    }

    @Override
    public Map<String, Object> updateClock(ClockTable clock) {
        String likeTime = clock.getLikeTime();
        String[] str = likeTime.split("-");
        String s = str[1];
        if(Integer.parseInt(s)<10){
            s="0"+s;
        }
        String s3 = str[2];
        if(Integer.parseInt(s3)<10){
            s3="0"+s3;
        }
        String time = "%"+str[0]+"-"+s+"-"+s3+"%";
        clock.setLikeTime(time);
        Map<String,Object> map = new HashMap<>();
        Integer integer = clockDao.updateClock(clock);
        if(integer>0){
            map.put("info","操作成功");
        }
        return map;
    }


}
